package com.ruoyi.project.drug.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.drug.domain.DrugSupplier;
import com.ruoyi.project.drug.service.IDrugSupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/drug/supplier")
public class DrugSupplierController extends BaseController {
    @Autowired
    private IDrugSupplierService drugSupplierService;

    /**
     * 查询【供应商】列表
     */
    //@PreAuthorize("@ss.hasPermi('system:supplier:list')")
    @GetMapping("/list")
    public TableDataInfo list(DrugSupplier drugSupplier)
    {
        startPage();
        List<DrugSupplier> list = drugSupplierService.selectDrugSupplierList(drugSupplier);
        return getDataTable(list);
    }

    /**
     * 导出【供应商】列表
     */
    //@PreAuthorize("@ss.hasPermi('system:supplier:export')")
    @Log(title = "【供应商】", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DrugSupplier drugSupplier)
    {
        List<DrugSupplier> list = drugSupplierService.selectDrugSupplierList(drugSupplier);
        ExcelUtil<DrugSupplier> util = new ExcelUtil<DrugSupplier>(DrugSupplier.class);
        return util.exportExcel(list, "supplier");
    }

    /**
     * 获取【供应商】详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:supplier:query')")
    @GetMapping(value = "/{supId}")
    public AjaxResult getInfo(@PathVariable("supId") Long supId)
    {
        return AjaxResult.success(drugSupplierService.selectDrugSupplierById(supId));
    }

    /**
     * 新增【供应商】
     */
    //@PreAuthorize("@ss.hasPermi('system:supplier:add')")
    @Log(title = "【供应商】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DrugSupplier drugSupplier)
    {
        return toAjax(drugSupplierService.insertDrugSupplier(drugSupplier));
    }

    /**
     * 修改【供应商】
     */
    //@PreAuthorize("@ss.hasPermi('system:supplier:edit')")
    @Log(title = "【供应商】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DrugSupplier drugSupplier)
    {
        return toAjax(drugSupplierService.updateDrugSupplier(drugSupplier));
    }

    /**
     * 删除【供应商】
     */
    //@PreAuthorize("@ss.hasPermi('system:supplier:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @DeleteMapping("/{supIds}")
    public AjaxResult remove(@PathVariable Long[] supIds)
    {
        return toAjax(drugSupplierService.deleteDrugSupplierByIds(supIds));
    }
}
